<?php
	/**
	 * This is a MetaControl class, providing a QForm or QPanel access to event handlers
	 * and QControls to perform the Create, Edit, and Delete functionality
	 * of the Articlecore class.  This code-generated class
	 * contains all the basic elements to help a QPanel or QForm display an HTML form that can
	 * manipulate a single Articlecore object.
	 *
	 * To take advantage of some (or all) of these control objects, you
	 * must create a new QForm or QPanel which instantiates a ArticlecoreMetaControl
	 * class.
	 *
	 * Any and all changes to this file will be overwritten with any subsequent
	 * code re-generation.
	 * 
	 * @package My Application
	 * @subpackage MetaControls
	 * property-read Articlecore $Articlecore the actual Articlecore data class being edited
	 * property QLabel $IdControl
	 * property-read QLabel $IdLabel
	 * property QTextBox $AsinControl
	 * property-read QLabel $AsinLabel
	 * property QTextBox $DetailPageURLControl
	 * property-read QLabel $DetailPageURLLabel
	 * property QTextBox $BindingControl
	 * property-read QLabel $BindingLabel
	 * property QTextBox $TitleControl
	 * property-read QLabel $TitleLabel
	 * property QListBox $ProductGroupControl
	 * property-read QLabel $ProductGroupLabel
	 * property QTextBox $ImageURLControl
	 * property-read QLabel $ImageURLLabel
	 * property-read string $TitleVerb a verb indicating whether or not this is being edited or created
	 * property-read boolean $EditMode a boolean indicating whether or not this is being edited or created
	 */

	class ArticlecoreMetaControlGen extends QBaseClass {
		// General Variables
		protected $objArticlecore;
		protected $objParentObject;
		protected $strTitleVerb;
		protected $blnEditMode;

		// Controls that allow the editing of Articlecore's individual data fields
		protected $lblId;
		protected $txtAsin;
		protected $txtDetailPageURL;
		protected $txtBinding;
		protected $txtTitle;
		protected $lstProductGroupObject;
		protected $txtImageURL;

		// Controls that allow the viewing of Articlecore's individual data fields
		protected $lblAsin;
		protected $lblDetailPageURL;
		protected $lblBinding;
		protected $lblTitle;
		protected $lblProductGroup;
		protected $lblImageURL;

		// QListBox Controls (if applicable) to edit Unique ReverseReferences and ManyToMany References

		// QLabel Controls (if applicable) to view Unique ReverseReferences and ManyToMany References


		/**
		 * Main constructor.  Constructor OR static create methods are designed to be called in either
		 * a parent QPanel or the main QForm when wanting to create a
		 * ArticlecoreMetaControl to edit a single Articlecore object within the
		 * QPanel or QForm.
		 *
		 * This constructor takes in a single Articlecore object, while any of the static
		 * create methods below can be used to construct based off of individual PK ID(s).
		 *
		 * @param mixed $objParentObject QForm or QPanel which will be using this ArticlecoreMetaControl
		 * @param Articlecore $objArticlecore new or existing Articlecore object
		 */
		 public function __construct($objParentObject, Articlecore $objArticlecore) {
			// Setup Parent Object (e.g. QForm or QPanel which will be using this ArticlecoreMetaControl)
			$this->objParentObject = $objParentObject;

			// Setup linked Articlecore object
			$this->objArticlecore = $objArticlecore;

			// Figure out if we're Editing or Creating New
			if ($this->objArticlecore->__Restored) {
				$this->strTitleVerb = QApplication::Translate('Edit');
				$this->blnEditMode = true;
			} else {
				$this->strTitleVerb = QApplication::Translate('Create');
				$this->blnEditMode = false;
			}
		 }

		/**
		 * Static Helper Method to Create using PK arguments
		 * You must pass in the PK arguments on an object to load, or leave it blank to create a new one.
		 * If you want to load via QueryString or PathInfo, use the CreateFromQueryString or CreateFromPathInfo
		 * static helper methods.  Finally, specify a CreateType to define whether or not we are only allowed to 
		 * edit, or if we are also allowed to create a new one, etc.
		 * 
		 * @param mixed $objParentObject QForm or QPanel which will be using this ArticlecoreMetaControl
		 * @param integer $intId primary key value
		 * @param QMetaControlCreateType $intCreateType rules governing Articlecore object creation - defaults to CreateOrEdit
 		 * @return ArticlecoreMetaControl
		 */
		public static function Create($objParentObject, $intId = null, $intCreateType = QMetaControlCreateType::CreateOrEdit) {
			// Attempt to Load from PK Arguments
			if (strlen($intId)) {
				$objArticlecore = Articlecore::Load($intId);

				// Articlecore was found -- return it!
				if ($objArticlecore)
					return new ArticlecoreMetaControl($objParentObject, $objArticlecore);

				// If CreateOnRecordNotFound not specified, throw an exception
				else if ($intCreateType != QMetaControlCreateType::CreateOnRecordNotFound)
					throw new QCallerException('Could not find a Articlecore object with PK arguments: ' . $intId);

			// If EditOnly is specified, throw an exception
			} else if ($intCreateType == QMetaControlCreateType::EditOnly)
				throw new QCallerException('No PK arguments specified');

			// If we are here, then we need to create a new record
			return new ArticlecoreMetaControl($objParentObject, new Articlecore());
		}

		/**
		 * Static Helper Method to Create using PathInfo arguments
		 *
		 * @param mixed $objParentObject QForm or QPanel which will be using this ArticlecoreMetaControl
		 * @param QMetaControlCreateType $intCreateType rules governing Articlecore object creation - defaults to CreateOrEdit
		 * @return ArticlecoreMetaControl
		 */
		public static function CreateFromPathInfo($objParentObject, $intCreateType = QMetaControlCreateType::CreateOrEdit) {
			$intId = QApplication::PathInfo(0);
			return ArticlecoreMetaControl::Create($objParentObject, $intId, $intCreateType);
		}

		/**
		 * Static Helper Method to Create using QueryString arguments
		 *
		 * @param mixed $objParentObject QForm or QPanel which will be using this ArticlecoreMetaControl
		 * @param QMetaControlCreateType $intCreateType rules governing Articlecore object creation - defaults to CreateOrEdit
		 * @return ArticlecoreMetaControl
		 */
		public static function CreateFromQueryString($objParentObject, $intCreateType = QMetaControlCreateType::CreateOrEdit) {
			$intId = QApplication::QueryString('intId');
			return ArticlecoreMetaControl::Create($objParentObject, $intId, $intCreateType);
		}



		///////////////////////////////////////////////
		// PUBLIC CREATE and REFRESH METHODS
		///////////////////////////////////////////////

		/**
		 * Create and setup QLabel lblId
		 * @param string $strControlId optional ControlId to use
		 * @return QLabel
		 */
		public function lblId_Create($strControlId = null) {
			$this->lblId = new QLabel($this->objParentObject, $strControlId);
			$this->lblId->Name = QApplication::Translate('Id');
			if ($this->blnEditMode)
				$this->lblId->Text = $this->objArticlecore->Id;
			else
				$this->lblId->Text = 'N/A';
			return $this->lblId;
		}

		/**
		 * Create and setup QTextBox txtAsin
		 * @param string $strControlId optional ControlId to use
		 * @return QTextBox
		 */
		public function txtAsin_Create($strControlId = null) {
			$this->txtAsin = new QTextBox($this->objParentObject, $strControlId);
			$this->txtAsin->Name = QApplication::Translate('Asin');
			$this->txtAsin->Text = $this->objArticlecore->Asin;
			$this->txtAsin->MaxLength = Articlecore::AsinMaxLength;
			return $this->txtAsin;
		}

		/**
		 * Create and setup QLabel lblAsin
		 * @param string $strControlId optional ControlId to use
		 * @return QLabel
		 */
		public function lblAsin_Create($strControlId = null) {
			$this->lblAsin = new QLabel($this->objParentObject, $strControlId);
			$this->lblAsin->Name = QApplication::Translate('Asin');
			$this->lblAsin->Text = $this->objArticlecore->Asin;
			return $this->lblAsin;
		}

		/**
		 * Create and setup QTextBox txtDetailPageURL
		 * @param string $strControlId optional ControlId to use
		 * @return QTextBox
		 */
		public function txtDetailPageURL_Create($strControlId = null) {
			$this->txtDetailPageURL = new QTextBox($this->objParentObject, $strControlId);
			$this->txtDetailPageURL->Name = QApplication::Translate('Detail Page U R L');
			$this->txtDetailPageURL->Text = $this->objArticlecore->DetailPageURL;
			$this->txtDetailPageURL->MaxLength = Articlecore::DetailPageURLMaxLength;
			return $this->txtDetailPageURL;
		}

		/**
		 * Create and setup QLabel lblDetailPageURL
		 * @param string $strControlId optional ControlId to use
		 * @return QLabel
		 */
		public function lblDetailPageURL_Create($strControlId = null) {
			$this->lblDetailPageURL = new QLabel($this->objParentObject, $strControlId);
			$this->lblDetailPageURL->Name = QApplication::Translate('Detail Page U R L');
			$this->lblDetailPageURL->Text = $this->objArticlecore->DetailPageURL;
			return $this->lblDetailPageURL;
		}

		/**
		 * Create and setup QTextBox txtBinding
		 * @param string $strControlId optional ControlId to use
		 * @return QTextBox
		 */
		public function txtBinding_Create($strControlId = null) {
			$this->txtBinding = new QTextBox($this->objParentObject, $strControlId);
			$this->txtBinding->Name = QApplication::Translate('Binding');
			$this->txtBinding->Text = $this->objArticlecore->Binding;
			$this->txtBinding->MaxLength = Articlecore::BindingMaxLength;
			return $this->txtBinding;
		}

		/**
		 * Create and setup QLabel lblBinding
		 * @param string $strControlId optional ControlId to use
		 * @return QLabel
		 */
		public function lblBinding_Create($strControlId = null) {
			$this->lblBinding = new QLabel($this->objParentObject, $strControlId);
			$this->lblBinding->Name = QApplication::Translate('Binding');
			$this->lblBinding->Text = $this->objArticlecore->Binding;
			return $this->lblBinding;
		}

		/**
		 * Create and setup QTextBox txtTitle
		 * @param string $strControlId optional ControlId to use
		 * @return QTextBox
		 */
		public function txtTitle_Create($strControlId = null) {
			$this->txtTitle = new QTextBox($this->objParentObject, $strControlId);
			$this->txtTitle->Name = QApplication::Translate('Title');
			$this->txtTitle->Text = $this->objArticlecore->Title;
			$this->txtTitle->MaxLength = Articlecore::TitleMaxLength;
			return $this->txtTitle;
		}

		/**
		 * Create and setup QLabel lblTitle
		 * @param string $strControlId optional ControlId to use
		 * @return QLabel
		 */
		public function lblTitle_Create($strControlId = null) {
			$this->lblTitle = new QLabel($this->objParentObject, $strControlId);
			$this->lblTitle->Name = QApplication::Translate('Title');
			$this->lblTitle->Text = $this->objArticlecore->Title;
			return $this->lblTitle;
		}

		/**
		 * Create and setup QListBox lstProductGroupObject
		 * @param string $strControlId optional ControlId to use
		 * @return QListBox
		 */
		public function lstProductGroupObject_Create($strControlId = null) {
			$this->lstProductGroupObject = new QListBox($this->objParentObject, $strControlId);
			$this->lstProductGroupObject->Name = QApplication::Translate('Product Group Object');
			$this->lstProductGroupObject->AddItem(QApplication::Translate('- Select One -'), null);
			$objProductGroupObjectArray = Articlecategory::LoadAll();
			if ($objProductGroupObjectArray) foreach ($objProductGroupObjectArray as $objProductGroupObject) {
				$objListItem = new QListItem($objProductGroupObject->__toString(), $objProductGroupObject->Id);
				if (($this->objArticlecore->ProductGroupObject) && ($this->objArticlecore->ProductGroupObject->Id == $objProductGroupObject->Id))
					$objListItem->Selected = true;
				$this->lstProductGroupObject->AddItem($objListItem);
			}
			return $this->lstProductGroupObject;
		}

		/**
		 * Create and setup QLabel lblProductGroup
		 * @param string $strControlId optional ControlId to use
		 * @return QLabel
		 */
		public function lblProductGroup_Create($strControlId = null) {
			$this->lblProductGroup = new QLabel($this->objParentObject, $strControlId);
			$this->lblProductGroup->Name = QApplication::Translate('Product Group Object');
			$this->lblProductGroup->Text = ($this->objArticlecore->ProductGroupObject) ? $this->objArticlecore->ProductGroupObject->__toString() : null;
			return $this->lblProductGroup;
		}

		/**
		 * Create and setup QTextBox txtImageURL
		 * @param string $strControlId optional ControlId to use
		 * @return QTextBox
		 */
		public function txtImageURL_Create($strControlId = null) {
			$this->txtImageURL = new QTextBox($this->objParentObject, $strControlId);
			$this->txtImageURL->Name = QApplication::Translate('Image U R L');
			$this->txtImageURL->Text = $this->objArticlecore->ImageURL;
			$this->txtImageURL->TextMode = QTextMode::MultiLine;
			return $this->txtImageURL;
		}

		/**
		 * Create and setup QLabel lblImageURL
		 * @param string $strControlId optional ControlId to use
		 * @return QLabel
		 */
		public function lblImageURL_Create($strControlId = null) {
			$this->lblImageURL = new QLabel($this->objParentObject, $strControlId);
			$this->lblImageURL->Name = QApplication::Translate('Image U R L');
			$this->lblImageURL->Text = $this->objArticlecore->ImageURL;
			return $this->lblImageURL;
		}



		/**
		 * Refresh this MetaControl with Data from the local Articlecore object.
		 * @param boolean $blnReload reload Articlecore from the database
		 * @return void
		 */
		public function Refresh($blnReload = false) {
			if ($blnReload)
				$this->objArticlecore->Reload();

			if ($this->lblId) if ($this->blnEditMode) $this->lblId->Text = $this->objArticlecore->Id;

			if ($this->txtAsin) $this->txtAsin->Text = $this->objArticlecore->Asin;
			if ($this->lblAsin) $this->lblAsin->Text = $this->objArticlecore->Asin;

			if ($this->txtDetailPageURL) $this->txtDetailPageURL->Text = $this->objArticlecore->DetailPageURL;
			if ($this->lblDetailPageURL) $this->lblDetailPageURL->Text = $this->objArticlecore->DetailPageURL;

			if ($this->txtBinding) $this->txtBinding->Text = $this->objArticlecore->Binding;
			if ($this->lblBinding) $this->lblBinding->Text = $this->objArticlecore->Binding;

			if ($this->txtTitle) $this->txtTitle->Text = $this->objArticlecore->Title;
			if ($this->lblTitle) $this->lblTitle->Text = $this->objArticlecore->Title;

			if ($this->lstProductGroupObject) {
					$this->lstProductGroupObject->RemoveAllItems();
				$this->lstProductGroupObject->AddItem(QApplication::Translate('- Select One -'), null);
				$objProductGroupObjectArray = Articlecategory::LoadAll();
				if ($objProductGroupObjectArray) foreach ($objProductGroupObjectArray as $objProductGroupObject) {
					$objListItem = new QListItem($objProductGroupObject->__toString(), $objProductGroupObject->Id);
					if (($this->objArticlecore->ProductGroupObject) && ($this->objArticlecore->ProductGroupObject->Id == $objProductGroupObject->Id))
						$objListItem->Selected = true;
					$this->lstProductGroupObject->AddItem($objListItem);
				}
			}
			if ($this->lblProductGroup) $this->lblProductGroup->Text = ($this->objArticlecore->ProductGroupObject) ? $this->objArticlecore->ProductGroupObject->__toString() : null;

			if ($this->txtImageURL) $this->txtImageURL->Text = $this->objArticlecore->ImageURL;
			if ($this->lblImageURL) $this->lblImageURL->Text = $this->objArticlecore->ImageURL;

		}



		///////////////////////////////////////////////
		// PROTECTED UPDATE METHODS for ManyToManyReferences (if any)
		///////////////////////////////////////////////





		///////////////////////////////////////////////
		// PUBLIC ARTICLECORE OBJECT MANIPULATORS
		///////////////////////////////////////////////

		/**
		 * This will save this object's Articlecore instance,
		 * updating only the fields which have had a control created for it.
		 */
		public function SaveArticlecore() {
			try {
				// Update any fields for controls that have been created
				if ($this->txtAsin) $this->objArticlecore->Asin = $this->txtAsin->Text;
				if ($this->txtDetailPageURL) $this->objArticlecore->DetailPageURL = $this->txtDetailPageURL->Text;
				if ($this->txtBinding) $this->objArticlecore->Binding = $this->txtBinding->Text;
				if ($this->txtTitle) $this->objArticlecore->Title = $this->txtTitle->Text;
				if ($this->lstProductGroupObject) $this->objArticlecore->ProductGroup = $this->lstProductGroupObject->SelectedValue;
				if ($this->txtImageURL) $this->objArticlecore->ImageURL = $this->txtImageURL->Text;

				// Update any UniqueReverseReferences (if any) for controls that have been created for it

				// Save the Articlecore object
				$this->objArticlecore->Save();

				// Finally, update any ManyToManyReferences (if any)
			} catch (QCallerException $objExc) {
				$objExc->IncrementOffset();
				throw $objExc;
			}
		}

		/**
		 * This will DELETE this object's Articlecore instance from the database.
		 * It will also unassociate itself from any ManyToManyReferences.
		 */
		public function DeleteArticlecore() {
			$this->objArticlecore->Delete();
		}		



		///////////////////////////////////////////////
		// PUBLIC GETTERS and SETTERS
		///////////////////////////////////////////////

		/**
		 * Override method to perform a property "Get"
		 * This will get the value of $strName
		 *
		 * @param string $strName Name of the property to get
		 * @return mixed
		 */
		public function __get($strName) {
			switch ($strName) {
				// General MetaControlVariables
				case 'Articlecore': return $this->objArticlecore;
				case 'TitleVerb': return $this->strTitleVerb;
				case 'EditMode': return $this->blnEditMode;

				// Controls that point to Articlecore fields -- will be created dynamically if not yet created
				case 'IdControl':
					if (!$this->lblId) return $this->lblId_Create();
					return $this->lblId;
				case 'IdLabel':
					if (!$this->lblId) return $this->lblId_Create();
					return $this->lblId;
				case 'AsinControl':
					if (!$this->txtAsin) return $this->txtAsin_Create();
					return $this->txtAsin;
				case 'AsinLabel':
					if (!$this->lblAsin) return $this->lblAsin_Create();
					return $this->lblAsin;
				case 'DetailPageURLControl':
					if (!$this->txtDetailPageURL) return $this->txtDetailPageURL_Create();
					return $this->txtDetailPageURL;
				case 'DetailPageURLLabel':
					if (!$this->lblDetailPageURL) return $this->lblDetailPageURL_Create();
					return $this->lblDetailPageURL;
				case 'BindingControl':
					if (!$this->txtBinding) return $this->txtBinding_Create();
					return $this->txtBinding;
				case 'BindingLabel':
					if (!$this->lblBinding) return $this->lblBinding_Create();
					return $this->lblBinding;
				case 'TitleControl':
					if (!$this->txtTitle) return $this->txtTitle_Create();
					return $this->txtTitle;
				case 'TitleLabel':
					if (!$this->lblTitle) return $this->lblTitle_Create();
					return $this->lblTitle;
				case 'ProductGroupControl':
					if (!$this->lstProductGroupObject) return $this->lstProductGroupObject_Create();
					return $this->lstProductGroupObject;
				case 'ProductGroupLabel':
					if (!$this->lblProductGroup) return $this->lblProductGroup_Create();
					return $this->lblProductGroup;
				case 'ImageURLControl':
					if (!$this->txtImageURL) return $this->txtImageURL_Create();
					return $this->txtImageURL;
				case 'ImageURLLabel':
					if (!$this->lblImageURL) return $this->lblImageURL_Create();
					return $this->lblImageURL;
				default:
					try {
						return parent::__get($strName);
					} catch (QCallerException $objExc) {
						$objExc->IncrementOffset();
						throw $objExc;
					}
			}
		}

		/**
		 * Override method to perform a property "Set"
		 * This will set the property $strName to be $mixValue
		 *
		 * @param string $strName Name of the property to set
		 * @param string $mixValue New value of the property
		 * @return mixed
		 */
		public function __set($strName, $mixValue) {
			try {
				switch ($strName) {
					// Controls that point to Articlecore fields
					case 'IdControl':
						return ($this->lblId = QType::Cast($mixValue, 'QControl'));
					case 'AsinControl':
						return ($this->txtAsin = QType::Cast($mixValue, 'QControl'));
					case 'DetailPageURLControl':
						return ($this->txtDetailPageURL = QType::Cast($mixValue, 'QControl'));
					case 'BindingControl':
						return ($this->txtBinding = QType::Cast($mixValue, 'QControl'));
					case 'TitleControl':
						return ($this->txtTitle = QType::Cast($mixValue, 'QControl'));
					case 'ProductGroupControl':
						return ($this->lstProductGroupObject = QType::Cast($mixValue, 'QControl'));
					case 'ImageURLControl':
						return ($this->txtImageURL = QType::Cast($mixValue, 'QControl'));
					default:
						return parent::__set($strName, $mixValue);
				}
			} catch (QCallerException $objExc) {
				$objExc->IncrementOffset();
				throw $objExc;
			}
		}
	}
?>